package com.uh.calculation.operator;

import ch.qos.logback.core.joran.conditional.ElseAction;
import com.uh.calculation.bean.*;
//import com.uh.calculation.util.GetFileds;
import com.uh.calculation.util.FormulaUtil;
import com.uh.calculation.util.GetBean;
import com.uh.calculation.util.GetFileds;
import com.uh.microservice.core.dao.JdbcDao;
import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
/**
 *  统计人员计算
 */
public class TjryOperator {
    private JdbcDao jdbcDao;

    private WarnJiSuanBean warnJiSuanBean;

    public TjryOperator(JdbcDao jdbcDao, WarnJiSuanBean warnJiSuanBean) {
        this.jdbcDao = jdbcDao;
        this.warnJiSuanBean = warnJiSuanBean;

    }

    public void jisuan(List<Map<String, Object>> ls, String key, String dimension) {
        this.warnJiSuanBean = warnJiSuanBean;
        if (ls==null||ls.size() == 0) {
            return;
        }
        int warnNum = 0;
        int i = 1;//统计变动次数
        String human = "firstName";//存储 填表人姓名
        String timeCode = "";
        for (Map<String, Object> map : ls) {
            String mapHuman = (String) map.get(key);
            timeCode = (String) map.get("time_code");
            if (mapHuman == null || "".equals(mapHuman)) {
                continue;
            }
            if (human.equals("firstName")) {
                human = mapHuman;
                i = 1;
                continue;
            }
            if (human.equals(mapHuman)) {
                i++;
                if (i >= 4) {
                    warnNum = 0;
                }
            } else {
                i = 1;
                warnNum = 20;
                human = mapHuman;
            }

        }
        WarnEnterpriseRecord warnEnterpriseRecord = new WarnEnterpriseRecord();
        warnEnterpriseRecord.setWarnFactor(String.valueOf(warnNum));
        warnEnterpriseRecord.setCreateTime(new Date());
        warnEnterpriseRecord.setDimension(dimension);//预警类型
        warnEnterpriseRecord.setYearIsMonth(timeCode);//预警时间
        warnEnterpriseRecord.setWarnType(warnJiSuanBean.getWarnType());
        if (warnJiSuanBean.getWarnEnterpriseRecords() == null) {
            warnJiSuanBean.setWarnEnterpriseRecords(new ArrayList<WarnEnterpriseRecord>());
        }
        warnJiSuanBean.getWarnEnterpriseRecords().add(warnEnterpriseRecord);
    }

}
